import time
from contextlib import contextmanager


@contextmanager
def timer_context(name="代码块"):
    start_time = time.perf_counter()
    try:
        yield
    finally:
        end_time = time.perf_counter()
        elapsed_time = end_time - start_time
        print(f"{name} 执行耗时: {elapsed_time:.6f} 秒")
